var role = require("../lib/role");
module.exports = {
	prefix: "/user_friend",
	get: {
		"/list": function() {
			var user = role.getUser(this);
			var friend_list = user.getFrinedList().map(function(friend) {
				return friend.getDetail();
			});
			this.body = ResponObj("json", friend_list);
		}
	},
	put: {
		"/add_friend/:friend_user_id": function() {
			var user = role.getUser(this);
			var friend_user_id = this.params.friend_user_id;
			user.addFriend(friend_user_id);
			var body = this.request.body;
			if (body.back_list) {
				var friend_list = user.getFrinedList().map(function(friend) {
					return friend.getDetail();
				});
				this.body = ResponObj("json", friend_list);
			} else {
				this.body = ResponObj("string", "好友添加成功");
			}
		}
	},
	delete: {
		"/remove_friend/:friend_user_id": function() {
			var user = role.getUser(this);
			var friend_user_id = this.params.friend_user_id;
			user.removeFriend(friend_user_id);
			var body = this.request.body;
			if (body.back_list) {
				var friend_list = user.getFrinedList().map(function(friend) {
					return friend.getDetail();
				});
				this.body = ResponObj("json", friend_list);
			} else {
				this.body = ResponObj("string", "好友删除成功");
			}
		}
	}
}